﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using RoyTools.D3Monitor.FormUI.Properties;
using System.Xml.Serialization;
using System.Xml;
using RoyTools.D3Monitor.FormUI.Helper;
using RoyTools.D3Monitor.FormUI.Loot;
using System.ComponentModel.DataAnnotations;

namespace RoyTools.D3Monitor.FormUI
{
    public partial class Default : Form
    {
        public Default()
        {
            InitializeComponent();
        }

        private void Main_Load(object sender, EventArgs e)
        {
            SetListView();
            var loadResult = ConfigHelper.LoadConfig();
            if (!string.IsNullOrWhiteSpace(loadResult))
            {
                MessageBox.Show(loadResult);
                FormHelper.Show(Program.Setup);
            }
            else
            {
                MonitorManager.SetLogMonitor();
            }
        }

        /// <summary>
        /// 设置日志分析表
        /// </summary>
        private void SetListView()
        {
            var properties = typeof(LootAnalyzerResultEntity).GetProperties().ToList();
            properties.ForEach(p =>
            {
                var columnText = p.Name;
                var attributes = p.GetCustomAttributes(true);
                DisplayAttribute attribute = null;
                if (attributes != null && attributes.Length > 0)
                {
                    attribute = (DisplayAttribute)attributes[0];
                }
                if (attribute != null)
                {
                    columnText = attribute.Name;
                }
                var columnHeader = new ColumnHeader();
                columnHeader.Text = columnText;
                lsvLog.Columns.Add(columnHeader);
            });
            lsvLog.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
        }

        private void tmiSetup_Click(object sender, EventArgs e)
        {
            FormHelper.Show(Program.Setup);
        }
    }
}
